package zjt.IO1;

import java.io.*;

public class demo6 {
    public static void main(String[] args) {


  /*  BufferedInputStream bufferedInputStream = null;
    BufferedOutputStream bufferedOutputStream = null;
        try {
            bufferedInputStream = new BufferedInputStream(new FileInputStream("c://1.jpg"));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        try {
            bufferedOutputStream = new BufferedOutputStream(new FileOutputStream("c://4.jpg"));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        //2.循环读写
        int read;
        try {
            while((read=bufferedInputStream.read())!=-1) {
                bufferedOutputStream.write(read);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                bufferedInputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                bufferedOutputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }*/
        BufferedReader bufferedReader = null;
        BufferedWriter bufferedWriter = null;

        try {
            bufferedReader = new BufferedReader(new FileReader("c://a.txt"));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        try {
            bufferedWriter = new BufferedWriter(new FileWriter("c://b.txt"));
        } catch (IOException e) {
            e.printStackTrace();
        }
        //2.循环读写
            char[] cc = new char[10];
            int len;
        try {
            while((len=bufferedReader.read(cc))!=-1) {
                bufferedWriter.write(cc, 0, len);
                bufferedWriter.flush();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally{
            try {
                bufferedReader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                bufferedWriter.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    }

